<%@page import="cn.copera.kaka.utils.Sign"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<c:set var="ctxStatic" value="${pageContext.request.contextPath}/static" />
<!DOCTYPE html>
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > 
    <title>店铺首页</title> 
    <meta name="viewport" content="height = device-height, width=device-width, initial-scale=1, user-scalable=no">
    <link href="${ctxStatic}/jqmobile/jquery.mobile-1.4.3/jquery.mobile-1.4.3.min.css" rel="stylesheet"> 
		<link rel="stylesheet" href="${ctxStatic}/kaka/css/ui-base.css">
        <link rel="stylesheet" href="${ctxStatic}/kaka/css/ui-box.css">
        <link rel="stylesheet" href="${ctxStatic}/kaka/css/ui-color.css">
		<link rel="stylesheet" href="${ctxStatic}/kaka/css/ui-res.css">
		<link rel="stylesheet" href="${ctxStatic}/kaka/css/ui-style.css">
		<link rel="stylesheet" href="${ctxStatic}/kaka/css/layout.css">
    
	<script src="${ctxStatic}/jquery/1.11.1/jquery-1.11.1.min.js"></script>
	<script src="${ctxStatic}/jqmobile/jquery.mobile-1.4.3/jquery.mobile-1.4.3.min.js"></script>
	<script type="text/javascript">
$(document).ready(function(){
	var width = $("#shopimage").width();
	$("#shopimage").height(width/1.6);
	$(window).bind("orientationchange", function( event ) { 
		if(event.orientation){ 
		      if(event.orientation == 'portrait'){ 
		    		var width = $("#shopimage").width();
		    		$("#shopimage").height(width/1.6);
		      } 
		      else if(event.orientation == 'landscape') { 
		    		var width = $("#shopimage").width();
		    		$("#shopimage").height(width/1.6);
		      } 
		   } 
		}); 	
if($("#message").val()=="您已兑换成功，无法撤销！"){
	$.mobile.loading( 'show', {
		  text: "您已兑换成功，无法撤销！",
		  textVisible: true,
		  theme: 'b',
		  textonly: true,
		  html: ""
		  });		
	setTimeout("hide()",2000);
}	
if($("#message").val()=="撤销成功"){
	$.mobile.loading( 'show', {
		  text: "撤销成功",
		  textVisible: true,
		  theme: 'b',
		  textonly: true,
		  html: ""
		  });		
	setTimeout("hide()",2000);
}
if($("#message").val()=="举报成功，卡卡将核实您的消息"){
	$.mobile.loading( 'show', {
		  text: "举报成功，卡卡将核实您的消息",
		  textVisible: true,
		  theme: 'b',
		  textonly: true,
		  html: ""
		  });		
	setTimeout("hide()",4000);
}
if($("#message").val()=="感谢您的建议，本店将据此提高服务质量（每月一次建议）"){
	$.mobile.loading( 'show', {
		  text: "感谢您的建议，本店将据此提高服务质量（每月一次建议）",
		  textVisible: true,
		  theme: 'b',
		  textonly: true,
		  html: ""
		  });		
	setTimeout("hide()",4000);
}
if($("#message").val()=="感谢您的建议，欢迎下个月继续提供建议"){
	$.mobile.loading( 'show', {
		  text: "感谢您的建议，欢迎下个月继续提供建议",
		  textVisible: true,
		  theme: 'b',
		  textonly: true,
		  html: ""
		  });		
	setTimeout("hide()",4000);
}

});
</script>
	<style type="text/css">
	  .textBlue{
	color:#02869e
}
.textG{
	font-size:1em;
}

.sList .percent{
	width:20%;
	display:block;
	float:left;
	font-size:1.0em;
}
.sList .percent .textBlue{
	font-size:1.0em;
	color:#02869e;
}
	</style>
</head>
<% 
String shopid = request.getSession().getAttribute("shopid").toString();
String openid = request.getSession().getAttribute("openid").toString();
String serverUrl = request.getSession().getAttribute("serverUrl").toString();
String shopname = request.getSession().getAttribute("shopname").toString();
String shopimage = request.getSession().getAttribute("shopimage").toString();
String signature= Sign.getSignatureShopIndex(shopid, openid);
%>
<body class="um-vp bg-gray" ontouchstart>
<div data-role="page" data-theme="none">
        <div id="page_0"  tabindex="0">
            <!--header开始-->
           <div id="header" class="uh c-m3 t-wh headerbg">
                <h1 class="hbg ulev0 ut-s tx-c headerPo" tabindex="0"><a href="${ctx}/searchList/${openid}" data-ajax="false"><span class="btnSearchB" ></span></a><span   id="headtitle">店铺首页</span><a href="${ctx}/report/${shopid}-${openid}" class="textReport" data-ajax="false">建议</a></h1>
            </div>
           
			<!--content开始-->
			<input type="hidden" value="${shopid}" name="shopid" id="shopid">
			<input type="hidden" value="${openid}" name="openid" id="openid">
			<input type="hidden" value="${serverUrl}" name="serverUrl" id="serverUrl">
			<input type="hidden" value="${shop.shop_name}" name="shopname" id="shopname">
			<input type="hidden" value="${shop.head_image}" name="shophead" id="shophead">
			<input type="hidden" value="${message}" name="message" id="message">
            <div id="content"  class="contentC">
			    <div class="shopView">
                	<a href="">
                	<c:choose>
                	<c:when test="${shop.head_image eq null or shop.head_image eq '无' }">
                	<div class="shopPic"><img src="${ctx}/images/logo_kaka.png"></div>
                	</c:when>
                	<c:otherwise>
                		<div class="shopPic"><img src="${serverUrl}${shop.head_image}"></div>
                		</c:otherwise>
                	</c:choose>	
						<div class="shopInfo">
							<ul class="infoList">
								<li class="tittle">${shop.shop_name}<c:if test="${shop.shop_name eq null}">无</c:if></li>
								<li class="text_info">${shop.address}<c:if test="${shop.address eq null}">无</c:if></li>
							</ul>
							
						</div></a>
                	<%-- <a href="/report/${shopid}" class="textReport">举报</a> --%>
                </div>
				<div class="shopPicBox">
                	<c:choose>
                	<c:when test="${shopImage.file_name eq null or shopImage.file_name eq '无'}">
                	<img src="${ctx}/images/shop01.jpg" id="shopimage">
                	</c:when>
                	<c:otherwise>
                		<img src="${serverUrl}${shopImage.file_name}" id="shopimage">
                		</c:otherwise>
                	</c:choose>	
                	
					<div class="introBox">
					<c:choose>
 					<c:when test="${praise.enabled eq '关闭' or praise.enabled eq null}"></c:when>
 					<c:otherwise>
						<p class="praise" id="que">${shop.total_count}<c:if test="${shop.total_count eq null}">0</c:if>个赞</p>
					</c:otherwise>
					</c:choose>						
						<ul class="social">
					<c:choose>
 					<c:when test="${praise.enabled eq '关闭' or praise.enabled eq null}"></c:when>
 					<c:otherwise>
							 <li><a class="praise" id="zan" <c:if test="${share.enabled eq '关闭' or share.enabled eq null}">style="margin-right: 0px;"</c:if>></a></li>
					</c:otherwise>
					</c:choose>
					<c:choose>
					<c:when test="${share.enabled eq '关闭' or share.enabled eq null}"></c:when>
					<c:otherwise>
							 <li><a class="share" href="#popupMenu" data-rel="popup" data-transition="pop"></a></li>
					</c:otherwise>
					</c:choose>							 
						</ul>
					</div>
					
				</div>
				<div class="shopInfoArea">
				   <div class="sList" >
						<a href="${ctx}/footPrint/${shopid}-${openid}-${track}">
							 <ul class="kaPrint">
							 	  <li>可用卡点：<span class="textO">${us.use_point}<c:if test="${us.use_point eq null}">0</c:if></span></li>
								  <li>最近足迹：<span class="textNear"><fmt:formatDate value="${date}" pattern="yyyy.MM.dd" type="date" dateStyle="long" /><c:if test="${content ne null or point ne null}">&nbsp</c:if><c:if test="${content eq null and point eq null}">本店暂无您的足迹</c:if>
								  <c:if test="${content ne null and praise1 eq null and share1 eq null and system eq null and advice eq null and guanzhu eq null and qiandao eq null}">消费一次，赠送${content}个卡点</c:if>
								  <c:if test="${point ne null and praise1 eq null and share1 eq null and system eq null and advice eq null and guanzhu eq null and qiandao eq null}">${point}个卡点兑换${econtent}</c:if><c:if test="${praise1 ne null}">${praise1}</c:if><c:if test="${share1 ne null}">${share1}</c:if><c:if test="${system ne null}">${system}</c:if><c:if test="${advice ne null}">${advice}</c:if><c:if test="${guanzhu ne null}">${guanzhu}</c:if><c:if test="${qiandao ne null}">${qiandao}</c:if></span></li>
						     </ul>
							 <span class="iconGo"></span>
						</a>
					</div>
					<div class="clear10"></div>
                    <div class="borderTop">
					 <%-- <c:if test="${message ne null}"><font style="margin-left: 15px; color: red;">${message}</font></c:if>  --%>
					<c:forEach items="${rules}" var="po">
					<div class="sList">
						<a href="${ctx}/exchangeSure/${shopid}-${po.id}-${openid}">
							 <ul class="kaPrint">
							 	  <li><span class="iconLeftgo"></span><span class="textKadian">${po.point_count}个卡点兑换${po.exchange_content}</span></li>
						     </ul>
							 <span class="iconGoB"></span>
						</a>
					</div>
					</c:forEach>
					<c:if test="${fn:length(rules)>0}"><div class="clear10"></div></c:if>
                    </div>
 					<c:choose>
 					<c:when test="${praise.enabled eq '关闭' or praise.enabled eq null}"></c:when>
 					<c:otherwise>                    
					<div class="sList borderTop" >
						 <a href="${ctx}/praise/${shopid}-${openid}" data-ajax="false">
						    <p class="kaSa"><span class="iconPraise"></span><span class="textG marT01">点赞<span class="textBlue">${praise.total_count}<c:if test="${praise.total_count eq null}">几</c:if></span>次，获赠<span class="textBlue">${praise.presenter_count}<c:if test="${praise.presenter_count eq null}">几</c:if></span>个卡点</span></p>
							<span class="percent"><span class="textBlue">${us.point_praise_count}<c:if test="${us.point_praise_count eq null}">0</c:if>/</span>${praise.total_count}<c:if test="${praise.total_count eq null}">0</c:if></span> 
							<span class="iconGoB"></span>
						 </a>
					</div>	
					</c:otherwise>
					</c:choose>
					<c:choose>
					<c:when test="${share.enabled eq '关闭' or share.enabled eq null}"></c:when>
					<c:otherwise>
					<div class="sList">
						 <a href="http://dyywx.shijun.org/kakawx/share/${shopid}-${openid}" target="_blank">
						    <p class="kaSa"><span class="iconShare"></span><span class="textG marT01">分享<span class="textBlue">${share.total_count}<c:if test="${share.total_count eq null}">几</c:if></span>次，获赠<span class="textBlue">${share.presenter_count}<c:if test="${share.presenter_count eq null}">几</c:if></span>个卡点</span></p>
							<span class="percent"><span class="textBlue">${us.share_count}<c:if test="${us.share_count eq null}">0</c:if>/</span>${share.total_count}<c:if test="${share.total_count eq null}">0</c:if></span> 
							<span class="iconGoB"></span>
						 </a>
					</div>	
					</c:otherwise>
					</c:choose>
              
					<c:if test="${praise.enabled eq '关闭' and share.enabled eq '关闭'}"><div class="clear10"></div></c:if>
					<div class="shopPicArea">
                    <c:forEach items="${shopImages}" var="sis">
                    <p>${sis.description}</p>
					    <img src="${serverUrl}${sis.file_name}">
                   	</c:forEach>
                    </div>
									
				</div>
            </div>
            <!--content结束-->
			
        </div>
<div data-role="popup" id="popupMenu" class="ui-content" data-theme="b" style="max-width:280px">
    <a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>
<p>点击右上角，发送给好友或者分享到朋友圈，即可获得卡点。</p>
</div>

</div>
<script type="text/javascript">
function hide(){
	$.mobile.loading( "hide" );
}
$('#zan').bind('click', function(){
	/* alert("haha"); */
	$.ajax( {
		url : '${ctx}/searchPraise',
		type : 'post',
		dataType : 'json',
		data : {shopid:$("#shopid").val(),openid:$("#openid").val()},
		success : function(json) {
			if (json.message == null) { 
				$("#que").empty();
				var $optbatch = $("<p class=\"praise\" id=\"que\">"+json.praise1+"个赞</p>");
					/* var $optbatch = $("<option value="+json.vols[i]+">"+json.vols[i]+"</option>"); */
					$('#que').append($optbatch);
					$.mobile.loading( 'show', {
						  text: "点赞成功",
						  textVisible: true,
						  theme: 'b',
						  textonly: true,
						  html: ""
						  });		
					setTimeout("hide()",2000);
			} else {
				$.mobile.loading( 'show', {
					  text: "今天点赞数已用完！",
					  textVisible: true,
					  theme: 'b',
					  textonly: true,
					  html: ""
					  });		
				setTimeout("hide()",2000);				
			}
		}
	});
	
});

</script>
</body> 
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
 /*
  * 注意：
  * 1. 所有的JS接口只能在公众号绑定的域名下调用，公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。
  * 2. 如果发现在 Android 不能分享自定义内容，请到官网下载最新的包覆盖安装，Android 自定义分享接口需升级至 6.0.2.58 版本及以上。
  * 3. 常见问题及完整 JS-SDK 文档地址：http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
  *
  * 开发中遇到问题详见文档“附录5-常见错误及解决办法”解决，如仍未能解决可通过以下渠道反馈：
  * 邮箱地址：weixin-open@qq.com
  * 邮件主题：【微信JS-SDK反馈】具体问题
  * 邮件内容说明：用简明的语言描述问题所在，并交代清楚遇到该问题的场景，可附上截屏图片，微信团队会尽快处理你的反馈。
  */
  wx.config({
	  debug: false,
	    appId: 'wx25d8154f7a1cd8a7',
	    timestamp: 1419835025,
	    nonceStr: '82693e11-b9bc-448e-892f-f5289f46cd0f',
	    signature: '<%=signature %>',
 jsApiList: [
		'checkJsApi',
		'onMenuShareTimeline',
		'onMenuShareAppMessage'
 ]
});
wx.ready(function () {
	  // 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口
	  //document.querySelector('#onMenuShareTimeline').onclick = function () {
	    wx.onMenuShareTimeline({
	      title: '<%=shopname %>',
	      desc: '我分享的店铺', // 分享描述
	      link: "http://dyywx.shijun.org/kakawx/shopShare/"+$("#shopid").val()+"-"+$("#openid").val(),
	      imgUrl: '<%=serverUrl %>'+'<%=shopimage %>',
	      trigger: function (res) {
	    	 // showDialog('用户点击分享到朋友圈');
	      },
	      success: function (res) {
	    	  alert("分享成功！");
	      },
	      cancel: function (res) {
	    	  
	      },
	      fail: function (res) {
	    	  alert("分享失败！");
	      }
	    });
	    wx.onMenuShareAppMessage({
	        title: '<%=shopname %>', // 分享标题
	        desc: '我分享的店铺', // 分享描述
	        link: "http://dyywx.shijun.org/kakawx/shopShare/"+$("#shopid").val()+"-"+$("#openid").val(), // 分享链接
	        imgUrl: '<%=serverUrl %>'+'<%=shopimage %>', // 分享图标
	        success: function () { 
	        	alert("发送成功！");
	           // 用户确认分享后执行的回调函数
	        },
	        cancel: function () { 
	        }
	    });	    
	    //alert('请点击右上角的分享到朋友圈进行分享');
	 // };
});
wx.error(function (res) {

});
</script>
</html>